package com.ruoyi.finance.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.finance.domain.Distributionrecord;
import com.ruoyi.finance.domain.DistributorRecordVO;
import com.ruoyi.finance.service.IDistributionrecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 分销记录表Controller
 * 
 * @author ruoyi
 * @date 2025-06-10
 */
@RestController
@RequestMapping("/distribution/distributionrecord")
public class DistributionrecordController extends BaseController
{
    @Autowired
    private IDistributionrecordService distributionrecordService;

    /**
     * 查询分销记录表列表
     */
    @PreAuthorize("@ss.hasPermi('distribution:distributionrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(DistributorRecordVO distributorRecordVO)
    {
        startPage();
        List<DistributorRecordVO> list = distributionrecordService.selectDistributionrecordList(distributorRecordVO);
        return getDataTable(list);
    }

    /**
     * 导出分销记录表列表
     */
    @PreAuthorize("@ss.hasPermi('distribution:distributionrecord:export')")
    @Log(title = "分销记录表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DistributorRecordVO distributorRecordVO)
    {
        List<DistributorRecordVO> list = distributionrecordService.selectDistributionrecordList(distributorRecordVO);
        ExcelUtil<DistributorRecordVO> util = new ExcelUtil<DistributorRecordVO>(DistributorRecordVO.class);
        util.exportExcel(response, list, "分销记录表数据");
    }

    /**
     * 获取分销记录表详细信息
     */
    @PreAuthorize("@ss.hasPermi('distribution:distributionrecord:query')")
    @GetMapping(value = "/{distributorId}")
    public AjaxResult getInfo(@PathVariable("distributorId") Integer distributorId)
    {
        return success(distributionrecordService.selectDistributionrecordByDistributorId(distributorId));
    }

    /**
     * 新增分销记录表
     */
    @PreAuthorize("@ss.hasPermi('distribution:distributionrecord:add')")
    @Log(title = "分销记录表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Distributionrecord distributionrecord)
    {
        return toAjax(distributionrecordService.insertDistributionrecord(distributionrecord));
    }

    /**
     * 修改分销记录表
     */
    @PreAuthorize("@ss.hasPermi('distribution:distributionrecord:edit')")
    @Log(title = "分销记录表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Distributionrecord distributionrecord)
    {
        return toAjax(distributionrecordService.updateDistributionrecord(distributionrecord));
    }

    /**
     * 删除分销记录表
     */
    @PreAuthorize("@ss.hasPermi('distribution:distributionrecord:remove')")
    @Log(title = "分销记录表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{distributorIds}")
    public AjaxResult remove(@PathVariable Integer[] distributorIds)
    {
        return toAjax(distributionrecordService.deleteDistributionrecordByDistributorIds(distributorIds));
    }
}
